package com.source.barcodeMachineRepairAndScrap.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.source.barcodeMachineRepairAndScrap.entity.BarcodeMachineScrap;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.source.barcodeMachineRepairAndScrap.vo.BarcodeMachineScrapVO;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author IceBerg777
 * @since 2021-03-07
 */
public interface BarcodeMachineScrapMapper extends BaseMapper<BarcodeMachineScrap> {

    String SELECT = "SELECT bms.* , su.`name` managerName \n" +
            "FROM barcode_machine_scrap bms , sys_user su \n" +
            "WHERE bms.managerId = su.userId AND bms.isDelete = 0 \n";


    @Select(value = "SELECT bms.* , su.`name` managerName \n" +
            "FROM barcode_machine_scrap bms , sys_user su \n" +
            "WHERE bms.managerId = su.userId AND bms.isDelete = 0\n" +
            "ORDER BY bms.managerId DESC ")
    IPage<BarcodeMachineScrapVO> findAllScrapOnPagination(Page<BarcodeMachineScrapVO> page);

    @Select(value = "SELECT bms.* , su.`name` managerName \n" +
            "FROM barcode_machine_scrap bms , sys_user su \n" +
            "WHERE bms.managerId = su.userId AND bms.isDelete = 0\n" +
            "AND CONCAT_WS(',',scrapId, barcodeMachineNumber, bms.createDate, scrapReason, scrapDate, su.`name`) LIKE #{keyWord} \n" +
            "ORDER BY bms.managerId DESC ")
    IPage<BarcodeMachineScrapVO> findByMultiKeysOnPagination(Page<BarcodeMachineScrapVO> page, String keyWord);

    @Select(value = "SELECT bms.* , su.`name` managerName \n" +
            "FROM barcode_machine_scrap bms , sys_user su \n" +
            "WHERE bms.managerId = su.userId AND bms.isDelete = 0 AND bms.scrapId = #{id} \n" +
            "ORDER BY bms.managerId DESC ")
    BarcodeMachineScrap findById(String id);

    @Select(SELECT + "ORDER BY bms.managerId DESC ")
    List<BarcodeMachineScrapVO> findAllScrap();
}
